package com.fhj.movie.adapter;

import java.util.LinkedList;

import com.android.volley.Network;
import com.android.volley.toolbox.NetworkImageView;
import com.fhj.movie.entity.FilmEntity;
import com.fhj.movie_fhj_01.R;
import com.fhj.utils.ImageDownload;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FilmGalleryAdapter extends BaseAdapter {

	private Context context;
	private LinkedList<FilmEntity> entities;
	private ImageDownload mImageDownload;

	public FilmGalleryAdapter(Context context, LinkedList<FilmEntity> entities) {

		this.entities = entities;
		this.context = context;
		
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return entities.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		GalleryViewHolder holder = null;
		if (arg1 == null) {
			arg1 = LayoutInflater.from(context).inflate(R.layout.film_gallery_item, arg2, false);
			holder = new GalleryViewHolder();
			holder.galleryView = (NetworkImageView)arg1.findViewById(R.id.film_gallery_img);
			holder.txtTittle = (TextView) arg1
					.findViewById(R.id.film_gallery_item_title);
			holder.txtImgXinpian = (ImageView) arg1
					.findViewById(R.id.film_gallery_lv_item_xinpian);
			holder.txtScore = (TextView) arg1
					.findViewById(R.id.film_gallery_lv_item_score);
			holder.txtScreening = (TextView) arg1
					.findViewById(R.id.film_gallery_lv_item_today);
			holder.txtBtn = (TextView) arg1
					.findViewById(R.id.film_gallery_lv_item_buyticket);
			arg1.setTag(holder);
		} else {
			holder = (GalleryViewHolder) arg1.getTag();
		}
		mImageDownload = ImageDownload.getInstance(context);
		FilmEntity filmEntity = entities.get(arg0);
		mImageDownload.downLoadImage(holder.galleryView,filmEntity.getLogo2());
		holder.txtTittle.setText(filmEntity.getName());
		if (filmEntity.getIsNew() == 0)
			holder.txtImgXinpian.setVisibility(View.GONE);
		holder.txtScore.setText(filmEntity.getGrade() + "分");
		holder.txtScreening.setText(filmEntity.getScreenings());
		return arg1;
	}

	static class GalleryViewHolder {
		NetworkImageView galleryView;
		TextView txtTittle;
		ImageView txtImgXinpian;
		TextView txtScore;
		TextView txtScreening;
		TextView txtBtn;
	}

}
